package web.fabrimind.sm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.fabrimind.bdm.domain.ProductionLine;
import web.fabrimind.common.annotation.Log;
import web.fabrimind.common.core.controller.BaseController;
import web.fabrimind.common.core.domain.AjaxResult;
import web.fabrimind.common.enums.BusinessType;
import web.fabrimind.sm.domain.ProductionTeam;
import web.fabrimind.sm.service.IProductionTeamService;
import web.fabrimind.common.utils.poi.ExcelUtil;
import web.fabrimind.common.core.page.TableDataInfo;

/**
 * 生产团队Controller
 * 
 * @author zhihui
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/sm/team")
public class ProductionTeamController extends BaseController
{
    @Autowired
    private IProductionTeamService productionTeamService;

    /**
     * 查询生产团队列表
     */
    @PreAuthorize("@ss.hasPermi('sm:team:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionTeam productionTeam)
    {
        startPage();
        List<ProductionTeam> list = productionTeamService.selectProductionTeamList(productionTeam);
        return getDataTable(list);
    }

    /**
     * 导出生产团队列表
     */
    @PreAuthorize("@ss.hasPermi('sm:team:export')")
    @Log(title = "生产团队", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductionTeam productionTeam)
    {
        List<ProductionTeam> list = productionTeamService.selectProductionTeamList(productionTeam);
        ExcelUtil<ProductionTeam> util = new ExcelUtil<ProductionTeam>(ProductionTeam.class);
        util.exportExcel(response, list, "生产团队数据");
    }

    /**
     * 获取生产团队详细信息
     */
    @PreAuthorize("@ss.hasPermi('sm:team:query')")
    @GetMapping(value = "/{teamId}")
    public AjaxResult getInfo(@PathVariable("teamId") Long teamId)
    {
        return success(productionTeamService.selectProductionTeamByTeamId(teamId));
    }

    /**
     * 新增生产团队
     */
    @PreAuthorize("@ss.hasPermi('sm:team:add')")
    @Log(title = "生产团队", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductionTeam productionTeam)
    {
        return toAjax(productionTeamService.insertProductionTeam(productionTeam));
    }

    /**
     * 修改生产团队
     */
    @PreAuthorize("@ss.hasPermi('sm:team:edit')")
    @Log(title = "生产团队", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionTeam productionTeam)
    {
        return toAjax(productionTeamService.updateProductionTeam(productionTeam));
    }

    /**
     * 删除生产团队
     */
    @PreAuthorize("@ss.hasPermi('sm:team:remove')")
    @Log(title = "生产团队", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teamIds}")
    public AjaxResult remove(@PathVariable Long[] teamIds)
    {
        return toAjax(productionTeamService.deleteProductionTeamByTeamIds(teamIds));
    }


}
